// Copyright (C) joyinter
// All rights reserved.
// 
// Author : dengxinguo
// Date   : 2004-12-6

#include "stdafx.h"

#include "roompage.h"
#include "roomlist.h"
#include "roomindex.h"
#include "cdvercluewnd.h"
#include "mainuiman.h"
#include <common/ui/utility.h>
#include "loginwnd.h"
#include "roompage.h"
#include <common/base/tinyxml.h>
#include "url.h"

extern CHAR joy_url_downloadcdaddr[];

IMPLEMENT_DYNAMIC(CJoyCDVerClueWnd, CJoyWnd)

//##ModelId=44C4B5E6016D
CJoyCDVerClueWnd::CJoyCDVerClueWnd(void)
{
    m_name = "cdverclue_window";
    m_skinArea  = true;

    m_btnStart     = NULL;
    m_btndownload  = NULL;
	
	m_btnquit=NULL;
  
}

//##ModelId=44C4B5E60178
CJoyCDVerClueWnd::~CJoyCDVerClueWnd(void)
{
}


BEGIN_MESSAGE_MAP(CJoyCDVerClueWnd, CJoyWnd)
    ON_WM_CREATE()
    ON_WM_NCHITTEST()
    ON_WM_DESTROY()
    ON_WM_TIMER()
END_MESSAGE_MAP()

//##ModelId=44C4B5E6017B
void CJoyCDVerClueWnd::OnCancel()
{
   
}

//##ModelId=44C4B5E6014A
void CJoyCDVerClueWnd::CM_Draw(Graphics& graph)
{
    int w = m_area.Width();
    int h = m_area.Height();
    // draw edge
    {
        Pen pen1(Color(0xFFCCCCCC), 2.0f);
        graph.DrawRectangle(&pen1, 0, 0, w, h);
        Pen pen2(Color(0xFF666666));
        graph.DrawRectangle(&pen2, 2, 2, w-6, h-6);
    }

    // draw back
    {
        Color c[5] = 
        {
            Color(0xFFFFFFFF),
            Color(0xFFFFFFFF),
            Color(0xFFE6E6E6),
            Color(0xFFFFFFFF),
            Color(0xFFFFFFFF),
        };
        REAL p[5] = 
        {
            0.0f, 0.022f, 0.022f, 0.4f, 1.0f,
        };
        JoyLinearFillRectV(graph,
            Rect(3, 3, w-7, h-7),
            c, p, 5);
    }

}

//##ModelId=44C4B5E60159
void CJoyCDVerClueWnd::CM_StartClick(CJoyButton*)
{
   m_Dlg->m_wnd->m_bStartGames=true;
    CDialog* pParent = (CDialog*)GetParent();
    if(pParent != NULL)
    {
        pParent->EndDialog(IDCANCEL);
    }
   
   
}

//##ModelId=44C4B5E60167
void CJoyCDVerClueWnd::CM_QuitClick(CJoyButton*)
{
    m_Dlg->m_wnd->m_bStartGames=false;
	 CDialog* pParent = (CDialog*)GetParent();
    if(pParent != NULL)
    {
        pParent->EndDialog(IDCANCEL);
    }

}
//##ModelId=44C4B5E6015C
void CJoyCDVerClueWnd::CM_DownLoadClick(CJoyButton*)
{
   
	m_Dlg->m_wnd->m_bStartGames=false;
	 CDialog* pParent = (CDialog*)GetParent();
    if(pParent != NULL)
    {
        pParent->EndDialog(IDCANCEL);
    }
	
	JoyOpenUrl(joy_url_downloadcdaddr);

}

//##ModelId=44C4B5E6016A
void CJoyCDVerClueWnd::CM_LoadSkin(CJoyXmlElement* pSkinElem)
{
    __super::CM_LoadSkin(pSkinElem);
	
    CWnd* pParent = GetParent();
    if(pParent != NULL)
    {
        pParent->MoveWindow(m_area);
        pParent->CenterWindow();
    }
}

//##ModelId=44C4B5E6017C
int CJoyCDVerClueWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CJoyWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

	CJoyImageCtrl *CDLogoImag=new CJoyImageCtrl();
	CDLogoImag->m_name="cd_logo";
	CDLogoImag->Create(this, CRect(0, 0, 10, 10));

    m_btndownload     = new CJoyButton();
    m_btndownload->m_name  = "btn_download";
    m_btndownload->Create(this, CRect(0, 0, 10, 10));
    m_btndownload->SetClickEvent(this, (CJoyButton::PClickEvent)CM_DownLoadClick);
    m_btndownload->m_hitTest = HTCLIENT;

	m_btnStart     = new CJoyButton();
    m_btnStart->m_name  = "btn_start";
    m_btnStart->Create(this, CRect(0, 0, 10, 10));
    m_btnStart->SetClickEvent(this, (CJoyButton::PClickEvent)CM_StartClick);
    m_btnStart->m_hitTest = HTCLIENT;

	m_btnquit     = new CJoyButton();
    m_btnquit->m_name  = "btn_quit";
    m_btnquit->Create(this, CRect(0, 0, 10, 10));
    m_btnquit->SetClickEvent(this, (CJoyButton::PClickEvent)CM_QuitClick);
    m_btnquit->m_hitTest = HTCLIENT;

	CJoyLabel *LabelVerHead = new CJoyLabel();
    LabelVerHead->m_name = "label_verhead";
    LabelVerHead->Create(this, CRect(0, 0, 10, 10));
    LabelVerHead->SetTextAlign(StringAlignmentNear);
	LabelVerHead->SetTextFormat(StringFormatFlagsDisplayFormatControl);
	
	CJoyLabel *LabelDownLoad = new CJoyLabel();
    LabelDownLoad->m_name = "label_download";
    LabelDownLoad->Create(this, CRect(0, 0, 10, 10));
    LabelDownLoad->SetTextAlign(StringAlignmentNear);
	LabelDownLoad->SetTextFormat(StringFormatFlagsDisplayFormatControl);
    
	CJoyLabel *Labeladvice = new CJoyLabel();
    Labeladvice->m_name = "label_advice";
    Labeladvice->Create(this, CRect(0, 0, 10, 10));
    Labeladvice->SetTextAlign(StringAlignmentNear);
	Labeladvice->SetVisible(false);
	
	CJoyLabel *LabelCDName = new CJoyLabel();
    LabelCDName->m_name = "label_cdname";
    LabelCDName->Create(this, CRect(0, 0, 10, 10));
    LabelCDName->SetTextAlign(StringAlignmentNear);

	
	JoyGetManager()->RegWnd(this);

	CString str;
	int i=m_cdCurrentVersion.GetLength()-4;
	if(i>0)
	{
		str=m_cdCurrentVersion.Right(i);
	}else
	{
		str=m_cdCurrentVersion;
	}
	CString str1;
	CString str2;
	str1=LabelVerHead->GetText();
	str2=Labeladvice->GetText();

 	LabelVerHead->SetText(str1+str+str2);
  
    return 0;
}

//##ModelId=44C4B5E60188
UINT CJoyCDVerClueWnd::OnNcHitTest(CPoint point)
{
    CPoint p(point);
    ScreenToClient(&p);
    UINT r = (UINT)DoHitTest(p);
    if(r != 0)
    {
        return r;
    }
    return (UINT)HTTRANSPARENT;
}

//##ModelId=44C4B5E6018B
void CJoyCDVerClueWnd::OnDestroy()
{
    JoyGetManager()->UnregWnd(this);

	
	CDialog* pParent = (CDialog*)GetParent();
    if(pParent != NULL)
    {
        pParent->EndDialog(IDCANCEL);
    }

    CJoyWnd::OnDestroy();
}



// CJoyCDVerClueDlg dialog

CJoyCDVerClueDlg* m_ClueDlg = NULL;

IMPLEMENT_DYNAMIC(CJoyCDVerClueDlg, CDialog)

//##ModelId=44C4B5E601AB
CJoyCDVerClueDlg::CJoyCDVerClueDlg(CWnd* pParent)
	: CDialog(CJoyCDVerClueDlg::IDD, pParent)
{
	m_wnd=(CJoyRoomPage *)pParent;
    m_ClueDlg   = this;
  
}

//##ModelId=44C4B5E601B5
CJoyCDVerClueDlg::~CJoyCDVerClueDlg()
{
    m_ClueDlg   = NULL;
}

//##ModelId=44C4B5E601BC
void CJoyCDVerClueDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

// CJoyCDVerClueDlg message handlers
BEGIN_MESSAGE_MAP(CJoyCDVerClueDlg, CDialog)
    ON_WM_CREATE()
    ON_WM_SIZE()
    ON_WM_NCHITTEST()
   // ON_WM_CLOSE()
END_MESSAGE_MAP()




//##ModelId=44C4B5E601C5
int CJoyCDVerClueDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;

	m_ClueWnd.m_cdCurrentVersion=m_wnd->m_cdProcessInfo.title;
    m_ClueWnd.Create(this, CRect(0, 0, 10, 10));
	m_ClueWnd.m_Dlg=this;

    return 0;
}

//##ModelId=44C4B5E601C8
void CJoyCDVerClueDlg::OnSize(UINT nType, int cx, int cy)
{
    CDialog::OnSize(nType, cx, cy);

    SetWindowRgn(CreateRoundRectRgn(0, 0, cx, cy, 2, 2), FALSE);
    
}

//##ModelId=44C4B5E601D5
UINT CJoyCDVerClueDlg::OnNcHitTest(CPoint point)
{
    CDialog::OnNcHitTest(point);
    return HTCAPTION;
}

